<?php
/**
 * Created by PhpStorm.
 * User: sun
 * Date: 18-3-31
 * Time: 上午10:14
 */

namespace App\Service;


class CellService
{
    /**
     * 获取等级转换
     */
    public function getRate($rawRate)
    {
        # 薄+字母
        if (mb_stripos( $rawRate,'薄') !== false) {
            return mb_ereg_replace('薄', 'B*', $rawRate);
        }
        if (mb_stripos($rawRate,'短') !== false) {
            return mb_ereg_replace('短', 'D*', $rawRate);
        }
        if (mb_stripos($rawRate,'窄') !== false) {
            return mb_ereg_replace('窄', 'Z*', $rawRate);
        }
        if ($rawRate == '漏刨') {
            return 'LB';
        }
        if ($rawRate == '小节') {
            return 'XJ';
        }
        if ($rawRate == '改尺') {
            return 'GC';
        }
        if ($rawRate == '红A2') {
            return 'A红2';
        }
        if ($rawRate == 'AB(弯)' || $rawRate == 'AB弯板' || $rawRate == 'AB(弯板)' || $rawRate == '弯AB') {
            return 'AB弯板';
        }
        if (mb_ereg_match('^[0-9]*P$', $rawRate) !== false) {
            preg_match('/^[0-9]*/',$rawRate,$matchs);
            return $this->covertNumToZh($matchs[0]).'拼';
        }
        return $rawRate;
    }

    private function covertNumToZh($num){
        $zhNum=['零','一','二','三','四','五','六','七','八','九'];
        $str = '';
        do {
            $str .= $zhNum[$num%10];
            $num  = (int)($num/10);
        }while(($num % 10 > 0));
        return $str;
    }


}